/*
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package au.com.domlogic.pvc.xhtml.element.builder;

import au.com.domlogic.pvc.core.element.ElementMoldBuilder;
import au.com.domlogic.pvc.xhtml.attr.ActionAttrMold;
import au.com.domlogic.pvc.xhtml.attr.MethodAttrMold;
import au.com.domlogic.pvc.xhtml.element.FormElementMold;

/**
 * This basic Model builder builds a model for a html form element with an 
 * actionAttrModel and methodAttrModel.  It also adds any fieldset models which
 * are the models for the fieldsets of the form.
 * 
 * @author Domenic Figliomeni
 */
public class FormMoldBuilder implements ElementMoldBuilder {

    private String action;
    private String method;

    /**
     * Default Constructor initializes the actionAttrModel and methodAttrModel attribute models
     * to be non null instances of the respective attribute models with null
     * values.  The fieldsetModels List is initialized as an empty ArrayList of
     * FieldsetElementModel.
     */
    protected FormMoldBuilder() {
    }

    /**
     * Alternative Constructor allows the devloper to set the values of the actionAttrModel
     * and methodAttrModel attributes when constructing a builder.
     * @param actionAttrModel
     * @param methodAttrModel
     */
    public FormMoldBuilder(String action, String method) {
        this.action = action;
        this.method = method;
    }

    /**
     * Alternative Constructor allows the developer to set the value of the actionAttrModel
     * attribute, while using the default "post" methodAttrModel
     * @param actionAttrModel
     */
    public FormMoldBuilder(String action) {
        this(action, "post");
    }

    @Override
    public FormElementMold buildElementMold() {
        FormElementMold form = new FormElementMold();
        form.addAttrMold(new ActionAttrMold(action)).addAttrMold(new MethodAttrMold(method));
        return form;
    }

    /**
     * @return the action
     */
    public String getAction() {
        return action;
    }

    /**
     * @param action the action to set
     */
    public void setAction(String action) {
        this.action = action;
    }

    /**
     * @return the method
     */
    public String getMethod() {
        return method;
    }

    /**
     * @param method the method to set
     */
    public void setMethod(String method) {
        this.method = method;
    }
}
